

#include "Undergraduate.h"
Undergraduate::Undergraduate(int id, string name,string skill)
            :Student(id,name),m_skill(skill){}

Undergraduate::Undergraduate() {
}

string Undergraduate::getSkill() const {return m_skill;}

void Undergraduate::reflect() {
    Student::reflect();
    cout << "skill: " << m_skill <<" 本科学生" <<endl;
}

string Undergraduate::serialize() {
    return "Id: " + to_string(getId()) + ", Name: " + getName() + ", Skill: " + m_skill;
}

void Undergraduate::deserialize(const string &info) {
    size_t pos1 = info.find("Id: ");
    size_t pos2 = info.find(", Name: ");
    size_t pos3 = info.find(", Skill: ");

    if (pos1 != string::npos && pos2 != string::npos && pos3 != string::npos) {
        int id = stoi(info.substr(pos1 + 4, pos2 - pos1 - 4));
        string name = info.substr(pos2 + 8, pos3 - pos2 - 8);
        string skill = info.substr(pos3 + 9);
        setId(id);
        setName(name);
        this->m_skill = skill;
    }
}

istream & Undergraduate::readFrom(istream &in) {
    cout << "Input id:" << endl;
    in >> m_id;
    cout << "Input name:" << endl;
    in >> m_name;
    cout << "Input skill:" << endl;
    in >> m_skill;
    return in;
}


Undergraduate::~Undergraduate(){}

ostream& operator<<(ostream& out, Undergraduate& stu) {
    out << "Id: " << stu.getId() << ", Name: " << stu.getName()<< ", Skill: " << stu.getSkill();
    return out;
}



